package com.huawei.appgallery.foundation.card.base.card;

import android.content.Context;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import androidx.databinding.ViewDataBinding;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.List;
import o.azb;
import o.cdb;
import o.cdg;
import o.cdn;
import o.cgz;
import o.chm;
import o.cke;
import o.dky.d;
import o.Logger;
import o.ContentManager;
import o.epw;
import o.CollectCheck;
import o.eqx;

public class BaseDistCard<T extends ViewDataBinding> extends cgz<T> {
    protected DownloadButton ˊ;
    protected String ˎ = "bannercard_horizental";
    protected cke ˏ = cke.DOWNLOAD_APP;
    protected String ॱ = "bannercard";

    public BaseDistCard(Context context) {
        this.ʼॱ = context;
    }

    public DownloadButton ʽ() {
        return this.ˊ;
    }

    public void ˋ(DownloadButton downloadButton) {
        this.ˊ = downloadButton;
    }

    public void ॱ(cke o_cke) {
        this.ˏ = o_cke;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
    }

    public void ˎ(BaseCardBean baseCardBean) {
        if (baseCardBean instanceof BaseDistCardBean) {
            BaseDistCardBean baseDistCardBean = (BaseDistCardBean) baseCardBean;
            ॱ(baseDistCardBean);
            if (!baseDistCardBean.ͺॱ()) {
                this.ˊ.setButtonDisable();
            }
        } else {
            Logger.e("BaseDistCard", "setCardData, data : " + (baseCardBean == null ? HwAccountConstants.NULL : baseCardBean.getClass().getSimpleName()));
        }
        super.ˎ(baseCardBean);
    }

    protected void ॱ(BaseDistCardBean baseDistCardBean) {
        if (this.ˊ == null) {
            return;
        }
        if (baseDistCardBean.ʾ() != null || baseDistCardBean.ͺ() == 14) {
            this.ˊ.setVisibility(0);
            this.ˊ.setParam(baseDistCardBean);
            ॱ(this.ˊ.ॱ());
            return;
        }
        this.ˊ.setVisibility(8);
    }

    public SpannableString ˏ(BaseCardBean baseCardBean) {
        if (baseCardBean instanceof BaseDistCardBean) {
            return ˏ((BaseDistCardBean) baseCardBean);
        }
        Logger.e("BaseDistCard", "setCardData, data : " + (baseCardBean == null ? HwAccountConstants.NULL : baseCardBean.getClass().getSimpleName()));
        return null;
    }

    protected void ˎ(ImageView imageView, String str, String str2) {
        ˋ(imageView, str, str2, true);
    }

    protected void ˋ(ImageView imageView, String str, String str2, boolean z) {
        if (imageView != null) {
            LayoutParams ˋ = ˋ(imageView);
            imageView.setLayoutParams(ˋ);
            String str3 = "NONE";
            str3 = "";
            if (2 == chm.ॱ().ˊ() || cdn.ॱॱ()) {
                str3 = this.ˎ;
                if (!TextUtils.isEmpty(str)) {
                    str2 = str;
                }
            } else {
                str3 = this.ॱ;
            }
            if (z) {
                ˊ(imageView, str2, str3, ˋ);
            } else {
                eqx.ˏ(imageView, str2, str3);
            }
        }
    }

    protected void ˊ(ImageView imageView, String str, String str2, LayoutParams layoutParams) {
        eqx.ˏ(imageView, str, str2);
    }

    private SpannableString ˏ(BaseDistCardBean baseDistCardBean) {
        int color = ContentManager.getInstant().getContext().getResources().getColor(d.ॱॱ);
        if (!(this.ʿ == null || this.ʿ.getTextColors().getDefaultColor() == color)) {
            color = this.ʿ.getTextColors().getDefaultColor();
        }
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(color);
        if (this.ˏ != cke.RESERVE_DOWNLOAD_APP) {
            return (this.ˏ == cke.DOWNLOAD_APP || this.ˊᐝ.ॱـ() == null) ? null : ˎ(baseDistCardBean, null);
        } else {
            SpannableString spannableString = new SpannableString(chm.ॱ().ˏ());
            spannableString.setSpan(foregroundColorSpan, 0, spannableString.length(), 33);
            return spannableString;
        }
    }

    protected SpannableString ˎ(BaseDistCardBean baseDistCardBean, SpannableString spannableString) {
        ApkUpgradeInfo ˋ = ˋ(this.ˊᐝ.ॱـ());
        if (ˋ == null || ˋ.ʼ() <= 0) {
            return spannableString;
        }
        String ˊ = epw.ˊ(baseDistCardBean.ˉ());
        String ˊ2 = epw.ˊ(ˋ.ʼ());
        spannableString = new SpannableString(ˊ2 + HwAccountConstants.BLANK + ˊ);
        spannableString.setSpan(chm.ॱ, ˊ2.length() + 1, spannableString.length(), 33);
        return spannableString;
    }

    protected LayoutParams ˋ(ImageView imageView) {
        LayoutParams layoutParams = imageView.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new LayoutParams(-1, -2);
        }
        int ॱ = azb.ॱ(imageView.getContext());
        layoutParams.width = -1;
        if (2 == chm.ॱ().ˊ() || cdn.ॱॱ()) {
            layoutParams.height = (int) (((double) ॱ) / this.ˊˊ);
        } else {
            layoutParams.height = (int) (((double) ॱ) / this.ˋˊ);
        }
        return layoutParams;
    }

    protected ApkUpgradeInfo ˋ(String str) {
        ApkUpgradeInfo ˊ = ((cdg) cdb.ॱ(cdg.class)).ˊ(str, false, 0);
        return ˊ != null ? ˊ : ((cdg) cdb.ॱ(cdg.class)).ˋ(str, false, 0);
    }

    public String ˏ(List<CardBean> list) {
        if (CollectCheck.isEmpty((List) list)) {
            return "";
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) instanceof BaseDistCardBean) {
                if (TextUtils.isEmpty(((BaseDistCardBean) list.get(i)).ͺˏ())) {
                    if (stringBuilder.length() != 0) {
                        stringBuilder.deleteCharAt(stringBuilder.length() - 1);
                    }
                    stringBuilder.append(";");
                } else {
                    stringBuilder.append(((BaseDistCardBean) list.get(i)).ͺˏ());
                    if (i != list.size() - 1) {
                        stringBuilder.append(",");
                    }
                }
            }
        }
        return stringBuilder.toString();
    }
}
